package com.acsior.hibernate.dao;

import static com.acsior.dac.impl.hibernate.vo.HibernatePersistantIntegerIdVO.ID;
import static org.hibernate.criterion.Restrictions.conjunction;
import static org.hibernate.criterion.Restrictions.eq;
import static org.hibernate.criterion.Restrictions.in;
import static org.hibernate.criterion.Restrictions.not;
import static org.hibernate.criterion.Restrictions.or;

import java.util.ArrayList;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Criterion;

import com.acsior.dac.impl.hibernate.dao.HibernateDAO;
import com.acsior.ddfn.impl.hibernate.dao.NomElementDAO;
import com.acsior.hibernate.vo.StructureVO;

/**
 * DAO for {@link StructureVO}
 * 
 * @author Г. Белев 22.08.2011
 */
public class StructureDAO extends NomElementDAO<StructureVO> {

	/** parent */
	public static final String PARENT = "parent";

	/** postalCode */
	public static final String POSTAL_CODE = "postalCode";

	/** isActive */
	private static final String IS_ACTIVE = "isActive";

	/** nomStructureType */
	private static final String NOM_STRUCTURE_TYPE = "nomStructureType";

	/**  */
	public StructureDAO() {
		super();
	}

	/** @see HibernateDAO#createCriteria() */
	@Override
	public Criteria createCriteria() {
		Criteria criteria = super.createCriteria();

		List<Integer> ids = new ArrayList<Integer>();
		ids.add(5);
		ids.add(6);

		Criterion first = conjunction().add(eq(IS_ACTIVE, true)).add(
				in(NOM_STRUCTURE_TYPE + "." + ID, ids));

		Criterion second = not(in(NOM_STRUCTURE_TYPE + "." + ID, ids));

		criteria.add(or(first, second));

		return criteria;
	}
}
